package cn.lili.modules.order.order.mapper;

import cn.lili.modules.order.order.entity.dos.OrderItemFlow;
import cn.lili.modules.order.order.entity.vo.OrderItemFlowUserVO;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 子订单流水数据处理层
 *
 * @author Chopper
 * @since 2020/11/17 7:35 下午
 */
public interface OrderItemFlowMapper extends BaseMapper<OrderItemFlow> {

    /**
     * 查询订单支付记录
     *
     * @param page         分页
     * @param queryWrapper 查询条件
     * @return 订单支付记录分页
     */
    @Select("select oif.id,oif.sn,oif.order_flow_sn,oif.order_sn,oif.order_item_sn,oif.goods_id,oif.user_id,oif.distribution_settlement_price,oif" +
            ".distribution_refund_price," +
            "oif.goods_name,oif.sku_id,oif.image,oif.category_id,oif.specs,store_name,oif.store_id,oif.create_time,oif.distribution_id,oif" +
            ".distribution_name" +
            " from li_order_item_flow oif left join li_order_item oi on oi.sn = oif.order_item_sn ${ew.customSqlSegment} ")
    Page<OrderItemFlowUserVO> getOrderFlowUserVOByCondition(Page<OrderItemFlowUserVO> page,
                                                            @Param(Constants.WRAPPER) Wrapper<OrderItemFlowUserVO> queryWrapper);


    @Select("select sum(oif.distribution_settlement_price) - sum(oif.distribution_refund_price) from li_order_item_flow oif" +
            " left join li_order_item oi on oi.sn = oif.order_item_sn ${ew.customSqlSegment}")
    Long amountOderFlowUserVOByCondition(@Param(Constants.WRAPPER) Wrapper<OrderItemFlowUserVO> queryWrapper);

}